document.write("<script src=\"" + context
		+ "/system/user/js/editpwd.js\"></script>");

/* 高级自定义密码验证 */
Ext.apply(Ext.form.VTypes, {
			/* val指当前文本框值，field指当前文本框组件 */
			password : function(val, field) {
				var rnt = false;
				/* 待比较目标文本框组件 */
				if (field.confirmTo) {
					var pwd = Ext.get(field.confirmTo);
					if (val == pwd.getValue()) {
						rnt = true;
					} else {
						// Ext.Msg.alert('提示', '密码确认错误！');
						rnt = false;
					}
				}
				return rnt;
			}
		});

Ext.onReady(function() {
	// This is an inner body element within the Details panel created to provide
	// a "slide in" effect
	// on the panel body without affecting the body's box itself. This element
	// is created on
	// initial use and cached in this var for subsequent access.
	var detailEl;
	
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';

	// This is the main content center region that will contain each example
	// layout panel.
	// It will be implemented as a CardLayout since it will contain multiple
	// panels with
	// only one being visible at any given time.
	var contentPanel = {
		id : 'content-panel',
		region : 'center', // this is what makes this panel into a region
		// within the containing layout
		layout : 'card',
		margins : '2 5 5 0',
		activeItem : 0,
		border : false,
		items : []
	};

	var tabs = new Ext.TabPanel({
				id : 'consoletabs',
				region : 'center', // a center region is ALWAYS
				// required for border layout
				closable : true,
				resizeTabs : true,
				minTabWidth : 150,
				tabWidth : 100,
				border : false,
				deferredRender : false,
				enableTabScroll : true,
				margins : '5 5 5 0',
				activeTab : 0, // first tab initially active
				items : []
			});

	tabs.add({
		id : 'desktop',
		title : '<font class="oaFont">我的桌面</font>',
		tabTip : '个人桌面',
		tabWidth : 100,
		iconCls : 'desktop',
		html : '<iframe id="desktop_frm" src="'
				+ context
				+ '/extframe/desktop.jsp" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>',
		closable : false
	}).show();

	// Go ahead and create the TreePanel now so that we can use it below
	var treePanel = new Ext.tree.TreePanel({
		id : 'tree-panel',
		// split : true,
		layout : 'fit',
		autoScroll : true,
		border : false,
		// tree-specific configs:
		rootVisible : false,
		lines : false,
		singleExpand : false,
		useArrows : true,
		dataUrl : context + '/system/module/menutreejson.jsp',

		root : new Ext.tree.AsyncTreeNode(),
		listeners : {
			'click' : function(node) {
				if (node && node.leaf) {
					if (node.attributes.mnblank == 1) {
						Ext.get('menuhref').dom.href = context
								+ node.attributes.mnurl;
						Ext.get('menuhref').dom.target = '_blank';
						Ext.get('menuhref').dom.click();
						// showWindow(node.attributes.mnurl, 800, 600);
					} else {
						var tabid = 'tab_' + node.attributes.realid;

						if (!Ext.getCmp(tabid)) {
							Ext.getCmp('consoletabs').add({
								id : tabid,
								title : '<font class="oaFont">' + node.text + '</font>',
								tabTip : node.attributes.mnmemo == ''
										? (node.parentNode.text + '/' + node.text)
										: node.attributes.mnmemo,
								iconCls : 'tabs',
								html : '<iframe src="'
										+ context
										+ node.attributes.mnurl
										+ '" id="'
										+ tabid
										+ '_frm" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>',
								closable : true
							}).show();
						} else {
							Ext.getCmp('consoletabs').setActiveTab(tabid);
							/*
							 * Ext.get(tabid + '_frm').dom.src = context +
							 * node.attributes.mnurl;
							 */
						}
					}
				} else if (node && !node.leaf && !node.isExpanded()) {
					node.expand(true);
				} else if (node && !node.leaf && node.isExpanded()) {
					node.collapse(true);
				}
			}

		}
	});

	treePanel.expandAll();

	var action = new Ext.Action({
				iconCls : 'collapse',
				tooltip : '收缩/展开左侧菜单区域',
				handler : function() {
					Ext.getCmp('btns').toggleCollapse(true);
					if (action.getIconClass() == 'collapse') {
						action.setIconClass('expand');
						action.setText('<font class="oaFont">展 开</font>');
					} else {
						action.setIconClass('collapse');
						action.setText('<font class="oaFont">收 缩</font>');
					}
				},
				text : '<font class="oaFont">收 缩</font>',
				scope : this
			});

	var viewport = new Ext.Viewport({
				layout : 'border',

				items : [{
							xtype : 'box',
							region : 'north',
							applyTo : 'header',
							height : 30
						}, {
							id : 'btns',
							region : 'west',
							baseCls : 'x-plain',
							split : true,
							// animCollapse:false,
							// animate: false,
							// collapseMode : 'mini',
							width : 170,
							minWidth : 170,
							maxWidth : 170,
							layout : 'fit',
							margins : '5 0 5 5',
							tbar : [' ', action, '-', {
										iconCls : 'pwd',
										tooltip : '可进行个人密码修改设置',
										handler : function() {
											editPWD();
										},
										text : '<font class="oaFont">密码管理</font>',
										scope : this
									}],
							items : [treePanel]
						}, tabs]
			});
        $('userNameSpan').innerHTML = userName;
        $('groupNameSpan').innerHTML = groupName;
});

function handleMenu(id, text, mnmemo, mnurl){
	var tabid = 'tab_' + id;
	
	if (!Ext.getCmp(tabid)) {
							Ext.getCmp('consoletabs').add({
								id : tabid,
								title : '<font class="oaFont">' + text + '</font>',
								tabTip : mnmemo,
								iconCls : 'tabs',
								html : '<iframe src="'
										+ mnurl
										+ '" id="'
										+ tabid
										+ '_frm" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>',
								closable : true
							}).show();
						} else {
							Ext.getCmp('consoletabs').setActiveTab(tabid);

						}
}

function handleClickNode(id){
	var node = Ext.getCmp('tree-panel').getNodeById(id);
	if(node != null){
		node.fireEvent('click', node);
	}
}

/* 退出系统 */
function logout() {
	Ext.MessageBox.confirm('确认', '确定退出系统？', function(e) {
				if (e == "yes") {
					document.location = context + '/system/logout.do';
				}
			});

}

function refre() {
	var tab = Ext.getCmp('consoletabs').getActiveTab();
	var frm = Ext.get(tab.id + '_frm');
	frm.dom.src = frm.dom.src;
}
